import Schema from 'async-validator'
class Validator {
  constructor(source, rules) {
    this.source = source;
    this.schema = new Schema(rules);
  }

  // eslint-disable-next-line valid-jsdoc
  /** 验证对象 */
  validate() {
    let source = this.source;
    let schema = this.schema;
    return new Promise(function(resolve, reject) {
      schema.validate(source, function(err, res) {
        if (err) {
          reject(err);
        }
        resolve(res);
      })
    })
  }

}

export default Validator;
